<div class="wide form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'service-form',
	'enableAjaxValidation'=>true,
)); ?>

	<p class="note"><?php echo Yii::t('main','Fields with')?> <span class="required">*</span> <?php echo Yii::t('main','are required.')?></p>

	<?php echo $form->errorSummary($model); ?>

	<?php if (isset($_GET['user_id'])) $model->user_id=$_GET['user_id']; ?>
	<?php echo $form->hiddenField($model,'user_id'); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'type'); ?>
		<?php echo $form->dropDownList($model,'type',Lookup::items('ServiceType')); ?>
		<?php echo $form->error($model,'type'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'ip'); ?>
		<?php echo $form->textField($model,'ip',array('size'=>25,'maxlength'=>25)); ?>
		<?php echo $form->error($model,'ip'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'cost'); ?>
		<?php echo $form->textField($model,'cost',array('size'=>12,'maxlength'=>12)); ?>
		<?php echo $form->error($model,'cost'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'packet_id'); ?>
		<?php echo $form->dropDownList($model,'packet_id',CHtml::listData(Packet::model()->active()->findAll(), 'id', 'name')); ?>
		<?php echo $form->error($model,'packet_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'speed_id'); ?>
		<?php echo $form->dropDownList($model,'speed_id',CHtml::listData(Speed::model()->active()->findAll(), 'id', 'name')); ?>
		<?php echo $form->error($model,'speed_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'comment'); ?>
		<?php echo $form->textField($model,'comment',array('size'=>60,'maxlength'=>128)); ?>
		<?php echo $form->error($model,'comment'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'start_date'); ?>
		<?php $this->widget('application.components.MyDatePicker', array(
			'model'=>$model,
			'attribute'=>'start_date',
		)); ?>
		<?php echo $form->error($model,'start_date'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'end_date'); ?>
		<?php $this->widget('application.components.MyDatePicker', array(
			'model'=>$model,
			'attribute'=>'end_date',
		)); ?>
		<?php echo $form->error($model,'end_date'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'is_blocked'); ?>
		<?php echo $form->checkBox($model,'is_blocked'); ?>
		<?php echo $form->error($model,'is_blocked'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'is_active'); ?>
		<?php echo $form->checkBox($model,'is_active'); ?>
		<?php echo $form->error($model,'is_active'); ?>
	</div>

	<?php
		$dialog='service-dialog';
		$grid='service-grid';			 //FIXME
	?>
	
	<div class="row buttons">
		<?php if (Yii::app()->request->isAjaxRequest) {?>
		
		<?php echo CHtml::ajaxSubmitButton($model->isNewRecord ? 'Create' : 'Save', 
			CHtml::normalizeUrl(array('service/create','render'=>false)),array(
				'success'=>'js: function(data) {
					$("#'.$grid.'").yiiGridView.update("'.$grid.'");
					$("#'.$dialog.'").dialog("close");
				}'),array('id'=>'service-submit')); ?>
		<?php echo Yii::t('main'," or ");?>
        <?php 
			echo CHtml::link(Yii::t('main', 'Cancel'),'#',array('class'=>'cancel','onclick'=>'$("#'.$dialog.'").dialog("close"); return false;'));
		?>
		
		<?php } else { ?>
		
		<?php echo CHtml::submitButton($model->isNewRecord ? Yii::t('main','Create') : Yii::t('main','Save')); ?>
		<?php echo Yii::t('main','or');?>
		<?php echo CHtml::link(Yii::t('main', 'Cancel'),Yii::app()->user->returnUrl,array('class'=>'cancel')); ?>

		<?php } ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->